//
//  CKMineViewController.m
//  ckjntiku
//  Created by Eileen Vivian on 2017/11/22.
//  Copyright © 2017年 Eileen Vivian. All rights reserved.
//
#import "CKMineViewController.h"

#import "CKCollectViewController.h"
#import "CKMistakeViewController.h"
#import "CKNotesViewController.h"
#import "CKHistoryViewController.h"
#import "CKSettingViewController.h"
#import "CKPersonInfoViewController.h"
#import "SZCalendarPicker.h"
#import "CKPersonInfoViewController.h"
@interface CKMineViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *mineTB;
@property (weak, nonatomic) IBOutlet UIImageView *touxiangImage;
@property (strong, nonatomic) NSArray *myArray1;
@property (strong, nonatomic) NSArray *myImagesArray1;
@property (strong, nonatomic) NSArray *myArray;
@property (strong, nonatomic) NSArray *myImagesArray;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) NSString *str;

@end
@implementation CKMineViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我";
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"calendar" highImage:@"calendar" target:self action:@selector(friendsClick:)];
      [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(post:) name:@"传值" object:nil];
//   [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(post:) name:@"传值1" object:nil];
    _touxiangImage.layer.cornerRadius = 30;
    _touxiangImage.layer.masksToBounds = YES;
    NSData * imageData = [XMGUserDefaults objectForKey:@"userIcon"];
    UIImage *image=[[UIImage alloc] initWithData:imageData];
    _touxiangImage.image = image;
    _touxiangImage.userInteractionEnabled = YES;             UITapGestureRecognizer*singleTap33=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toCityByClicked:)];
    singleTap33.numberOfTouchesRequired = 1; //手指数
    singleTap33.numberOfTapsRequired = 1; //tap次数
    singleTap33.delegate= self;
    _touxiangImage.contentMode = UIViewContentModeScaleToFill;
    [_touxiangImage addGestureRecognizer:singleTap33];
    self.myArray=@[@"答题提醒",@"我的错题",@"我的笔记",@"浏览历史"];
    self.myImagesArray =@[@"expire",@"deal",@"log",@"sous"];
    self.myArray1=@[@"其他设置",@"版本更新"];
    self.myImagesArray1 =@[@"set",@"update"];
    _mineTB.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
-(void)post:(NSNotification *)no{
    _nameLabel.text = [NSString stringWithFormat:@"%@",no.object];
    NSData * imageData = [XMGUserDefaults objectForKey:@"userIcon"];
    UIImage *image=[[UIImage alloc] initWithData:imageData];
    _touxiangImage.image = image;
}
-(void)toCityByClicked:(id)sender{
    CKPersonInfoViewController * activityVC = [[CKPersonInfoViewController alloc]init];
    [self.navigationController pushViewController:activityVC animated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.myArray.count;
    }else{
        return self.myArray1.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = self.myArray[indexPath.row];
        cell.imageView.image = [UIImage imageNamed:self.myImagesArray[indexPath.row]];
    }else{
        cell.textLabel.text = self.myArray1[indexPath.row];
        cell.imageView.image = [UIImage imageNamed:self.myImagesArray1[indexPath.row]];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            CKCollectViewController * ckCollectVC = [[CKCollectViewController alloc]init];
            [self.navigationController pushViewController:ckCollectVC animated:YES];
        }else if (indexPath.row == 1){
            CKMistakeViewController * ckMistakeVC = [[CKMistakeViewController alloc]init];
            [self.navigationController pushViewController:ckMistakeVC animated:YES];
        }else if (indexPath.row == 2){
            CKNotesViewController * ckNoteVC = [[CKNotesViewController alloc]init];
            [self.navigationController pushViewController:ckNoteVC animated:YES];
        }else if (indexPath.row == 3){
            CKHistoryViewController * ckHistoryVC = [[CKHistoryViewController alloc]init];
            [self.navigationController pushViewController:ckHistoryVC animated:YES];
        }
    }else {
        if (indexPath.row ==0) {
            CKSettingViewController * ckSettingVC = [[CKSettingViewController alloc]init];
            [self.navigationController pushViewController:ckSettingVC animated:YES];
        }else{
            NSLog(@"版本更新");
        }
    }
    }
-(void)friendsClick:(UIBarButtonItem*)item{
    SZCalendarPicker *calendarPicker = [SZCalendarPicker showOnView:self.view];
    calendarPicker.today = [NSDate date];
    calendarPicker.date = calendarPicker.today;
    calendarPicker.frame = CGRectMake(0, 100, self.view.frame.size.width, 352);
    calendarPicker.calendarBlock = ^(NSInteger day, NSInteger month, NSInteger year){
    };
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 8;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
